﻿using System;
using System.Drawing;
using System.Windows.Forms;
using GifTest;

namespace test._99_test.time._2012_02_09_113240
{
    public partial class Form4 : Form
    {
        AnimateImage image;

        public Form4()
        {
            InitializeComponent();

            image = new AnimateImage(Image.FromFile(@"C:\Documents and Settings\Administrator\My Documents\My Pictures\未命名.gif"));
            image.OnFrameChanged += new EventHandler<EventArgs>(image_OnFrameChanged);
            SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);
        }

        private void Form4_Load(object sender, EventArgs e)
        {
            image.Play();
        }

        private void image_OnFrameChanged(object sender, EventArgs e)
        {
            Invalidate();
        }

        private void Form4_Paint(object sender, PaintEventArgs e)
        {
            lock (image.Image)
            {
                e.Graphics.DrawImage(image.Image, new Point(0, 0));
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (button1.Text.Equals("Stop"))
            {
                image.Stop();
                button1.Text = "Play";
            }
            else
            {
                image.Play();
                button1.Text = "Stop";
            }
            Invalidate();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            image.Reset();
            button1.Text = "Play";
            Invalidate();
        }
    }
}